<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"/>
<html>
<head>
    <title>主任信箱</title>
    <%@include file="../common/_head.jsp" %>
    <script>
        function sendMessage() {
            // 方法1
            var title = $('#message_title').val();
            var classify = $('#message_classify').val();
            var content = $('#message_content').val().replace(/\n|\r\n/g,"<br/>");
            var params = {};
            params.title = title;
            params.classify = classify;
            params.studentMessage = content;
            $.ajax({
                type: "post",
                url: "${ctx}/message/student/send",
                data: params,
                dataType: "json",
                success: function (re) {
                    if(true==re.success){
                        $.toast("操作成功", function () {
                            window.location = "${ctx}/student/index";
                        });
                    }else {
                        $.toast("操作失败，请联系管理员", "cancel");
                    }
                },
                error: function (re) {
                    $.toast("网络请求失败，请联系管理员", "cancel");
                }
            });
            // 方法2
            <%--$('form')[0].submit(function () {--%>
                <%--$.toast("操作成功", function () {--%>
                    <%--window.location = "${ctx}/student/index";--%>
                <%--});--%>
            <%--});--%>
        }
        function resetForm() {
            $('#message_form')[0].reset();
        }
        function cancel() {
            window.location = "${ctx}/student/index";
        }
    </script>
</head>
<body ontouchstart>
<div class="weui-tab">
    <div class="weui-navbar">
        <a class="weui-navbar__item weui-bar__item--on" href="#tab-message-write">
            写信
        </a>
        <a class="weui-navbar__item" href="#tab-message-past">
            过去的信
        </a>
    </div>
    <div class="weui-tab__bd">
        <div id="tab-message-write" class="weui-tab__bd-item weui-tab__bd-item--active">
                <div class="weui-cells weui-cells_form">
                    <form id="message_form" action="${ctx}/message/student/send">
                        <div class="weui-cell">
                            <label class="weui-label">标题</label>
                            <div class="weui-cell__bd">
                                <input class="weui-input" type="text" name="title" id="message_title" placeholder="请重点突出，简单明了">
                            </div>
                        </div>
                        <div class="weui-cell">
                            <label class="weui-label">类型</label>
                            <div class="weui-cell__bd">
                                <select class="weui-select" name="classify" id="message_classify">
                                    <option>请选择类型</option>
                                    <option value="1">教学</option>
                                    <option value="2">见习、实训、实习</option>
                                    <option value="3">生活</option>
                                    <option value="4">其他</option>
                                </select>
                            </div>
                        </div>
                        <div class="weui-cell">
                            <label class="weui-label">内容</label>
                        </div>
                        <div class="weui-cell">
                            <div class="weui-cell__bd">
                                <textarea class="weui-textarea" name="studentMessage" id="message_content" placeholder="请具体讲问题描述清楚，重点突出、细节完整" rows="10"></textarea>
                            </div>
                        </div>
                    </form>
                </div>
                <div style="text-align:center">
                    <a href="javascript:;" onclick="sendMessage()" class="weui-btn weui-btn_primary weui-btn_medium">发送</a>
                    <a href="javascript:;" onclick="resetForm()" class="weui-btn weui-btn_primary weui-btn_medium">重置</a>
                    <a href="javascript:;" onclick="cancel()" class="weui-btn weui-btn_primary weui-btn_medium">取消</a>
                </div>
        </div>
        <div id="tab-message-past" class="weui-tab__bd-item"></div>
    </div>
</div>
<%@include file="../common/_foot.jsp" %>
</body>
</html>
